@use "sass:math";
@import "./../abstracts/index";

@keyframes show {
  from {
    @include dropdown-animation-hidden;
  }
  to {
    @include dropdown-animation-visible;
  }
}

@keyframes hide {
  from {
    @include dropdown-animation-visible;
  }
  to {
    @include dropdown-animation-hidden;
  }
}

.dropdown {
  position: relative;

  &__label {
    display: block;
    width: 100%;
    appearance: none;
    border: none;
    outline: none;
    font-size: inherit;
    color: inherit;
    text-decoration: inherit;
    text-transform: inherit;
    text-align: center;
    padding: $dropdown-label-padding;
    background-color: $dropdown-label-background-color;
    border-radius: $dropdown-border-radius;
    &:after {
      display: none;
      content: '';
      width: 100%;
      height: $dropdown-options-space-from-label * 1.5;
      position: absolute;
      top: 100%;
      left: 0;
      background-color: transparent;
    }
  }

  &__options {
    visibility: visible;
    z-index: 1;
    min-width: 110px;
    max-height: 50vh;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%, 0);
    list-style: none;
    font-size: 13px;
    background-color: $dropdown-options-background-color;
    border-radius: $dropdown-border-radius;
    box-shadow: $shadow-soft;
    overflow: auto;
    animation: hide math.div($dropdown-animation-timing, 2)  ease forwards;

    @include up-to-mobile {
      top: 75%;
    }

    &:before {
      content: '';
      width: 0;
      height: 0;
      position: absolute;
      top: 0;
      left: 50%;
      border-style: solid;
      border-width: 0 $dropdown-arrow-size math.div($dropdown-arrow-size, 2) $dropdown-arrow-size;
      border-color: transparent transparent $dropdown-options-background-color transparent;
      transform: translate(-50%, -100%);
    }
  }

  &__option {
    a {
      display: block;
      padding: $dropdown-option-padding;
      color: rgba(black, .6);
      text-decoration: none;
      border-bottom: 1px solid $dropdown-option-border-bottom-color;
      transition: background-color .3s ease, color .3s ease;
      text-transform: none;
      font-weight: normal;
      &:hover,
      &:focus {
        color: $color-primary;
        background-color: rgba($color-neutral-dark, .025);
      }
    }
    &:last-child a {
      border-bottom: none;
    }
  }

  &:hover &__label:after, &:hover &__options,
  &:focus &__label:after, &:focus &__options {
    display: block;
  }

  &:hover &__options,
  &:focus &__options {
    animation: show $dropdown-animation-timing ease forwards;
  }
}
